package common

import (
	"go-gin-vue/ginessential/model"

	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/postgres"
)

var DB *gorm.DB

//开启连接池
func InitDB() *gorm.DB {
	db, err := gorm.Open("postgres", "host=localhost port=5432 user=postgres dbname=study password=97301335 sslmode=disable")

	if err != nil {
		panic("fail to connect database, err: " + err.Error())
	}

	db.AutoMigrate(&model.User{})
	
	DB = db

	return db
}

//定义方法获取DB实例
func GetDB() *gorm.DB {
	return DB
}
